import os from 'os';
import path from "path";


export function getIconClasses(){
  let filePath = path.resolve('/static/iconfont/iconfont.css');
  let file = loadFile(filePath);
  let icons = file.split(os.EOL);
  let classes = [];
  for (var i = 0; i < icons.length; i++) {
    var icon = icons[i];
    if (icon.includes('icon-')) {
      var className = icon.split('.')[1].split(':')[0];
      classes.push(className);
    }
  }
  return classes;
}

export function loadFile(name) { // name为文件所在位置
  let xhr = new XMLHttpRequest(),
    okStatus = document.location.protocol === "file:" ? 0 : 200;
  xhr.open('GET', name, false);
  xhr.overrideMimeType("text/html;charset=utf-8");//默认为utf-8
  xhr.send(null);
  return xhr.status === okStatus ? xhr.responseText : null;
}
